﻿using System.Reflection;
using System.Configuration;
using AzManContrib.MVC;
using AzManContrib.MVC.Initialization;

[assembly: WebActivator.PostApplicationStartMethod(typeof($rootnamespace$.App_Start.AzManContribBootStrapper), "Start")]
namespace $rootnamespace$.App_Start
{
    public static class AzManContribBootStrapper
    {
        public static void Start()
        {
            string applicationName = AzmanModuleSection.Instance != null &&
                                     !string.IsNullOrEmpty(AzmanModuleSection.Instance.Application)
                                         ? AzmanModuleSection.Instance.Application
                                         : Assembly.GetExecutingAssembly().GetName().Name;

            ConnectionStringSettings azManConnectionString =
                AzmanModuleSection.Instance != null && !string.IsNullOrEmpty(AzmanModuleSection.Instance.ConnectionString)
                    ? ConfigurationManager.ConnectionStrings[AzmanModuleSection.Instance.ConnectionString]
                    : ConfigurationManager.ConnectionStrings[0];

            AzMan.Default(defaults => defaults
                                      .UI()
                                      .DeniedBehavior()
                                      .Disable() // You might also use Hide() || SetCSSClass("ClassName") || NoOutput()
                );
            AzMan.Initialize<Asynchronously>(
                new InitializationContext(azManConnectionString.ConnectionString, applicationName),
                init => init
                         .When()
                         .AccessCheck()
                         .Deny() // You might also use Throws() || Accept()
                );
        }
    }
}
